from ninja import Router
from asgiref.sync import sync_to_async
from django.shortcuts import get_object_or_404

from waitlists.models import WaitlistEntry
from waitlists.schemas import WaitlistEntryListSchema

router = Router()


@router.get('', response=list[WaitlistEntryListSchema])
async def list_waitlist_entries(request):
    data = await sync_to_async(list)(
        WaitlistEntry.objects.all()
    )
    return data


@router.get('/{entry_id}', response=WaitlistEntryListSchema)
async def get_waitlist_entry(request, entry_id: int):
    instance = await sync_to_async(get_object_or_404)(WaitlistEntry, pk=entry_id)
    return instance
